package com.cj.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.jfinal.core.Controller;

public class LoginInterceptor implements Interceptor {

	@Override
	public void intercept(ActionInvocation ai) {
		Controller controller = ai.getController();
		String url = controller.getRequest().getRequestURI();
		if("/".equals(url) || "/employee/login".equals(url)) {
			ai.invoke();
			return;
		}
		Object employee = controller.getSession().getAttribute("employee");
		if(employee == null) {
			controller.redirect("/");
		} else {
			ai.invoke();
		}
	}
}
